# -*- coding:utf-8 -*-
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
class Solution:
    # 返回ListNode
    def ReverseList(self, pHead):
        if pHead == None:
            return None
        
        p = pHead
        q = pHead.next
        r = pHead.next
        
        if q == None:
            return pHead
        p.next = None
        while (r):
            r = r.next
            q.next = p
            p = q
            if r != None:
                q = r
        
        return q
        
        # write code here